from django.http import JsonResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from feedback.forms import CreateFeedback
from feedback.models import Feedback


def index(request):
    return render(request, 'feedback/index.html')

def new(request):
    title = '留言-量子企业数据智能分析系统-专注企业加速'
    feedback = Feedback()
    return render(request, 'feedback/new.html', locals())

@csrf_exempt
def create(request):
    if request.method == 'POST':
        feedback = CreateFeedback(data=request.POST)
        if feedback.is_valid():
            feedback.save()
            return JsonResponse({"success" : 'true', "msg" : '感谢您的支持，我们会尽快回复您的留言！'})
        else:
            return  JsonResponse(feedback.errors)
